//封装 AuthRoute 路由鉴权高阶组件，实现未登录拦截，并跳转到登录页面
import React from 'react'
import { useSelector } from 'react-redux'
import { Navigate, useLocation } from 'react-router-dom'

function AuthRouter({ children }) {
    //获取store的信息
    const user=useSelector(store=>store.user)
    //获取当前路径信息
    const location=useLocation()
    // console.log(location);
    return (
        <>
        {/* 是否登录，登录了就跳转到用户信息页，否则就是去登录页 */}
            {user.isLogged?children:<Navigate to='/authForm' state={{preLocation:location.pathname}} ></Navigate>}
        </>
    )
}

export default AuthRouter